﻿Ext.define('Wiztop.controller.Home', {
    extend: 'Ext.app.Controller',
    config: {
        refs: {
            homeView: {
                selector: 'homeview',
                xtype: 'homeview',
                autoCreate: true
            },
            btnDz: '#btnDz',
            btnBg: '#btnBg',
            btnFjz: '#btnFjz',
            btnQt: '#btnQt',
            btnMy: '#btnMy'
        },
        control: {
            btnDz: {
                tap: 'showMainDz'
            },
            btnBg: {
                tap: 'showMainBg'
            },
            //            btnFjz: {
            //                tap: 'showMainFjz'
            //            },
            btnQt: {
                tap: 'showMainQt'
            },
            btnMy: {
                tap: 'showMy'
            }
        },
        routes: {
            'home': 'showHomeView'
        }
    },
    showHomeView: function () {
        Ext.Viewport.setActiveItem(this.getHomeView());
    },
    showMainDz: function () {
        //        //获取会议文档
        if (sessionStorage.RoleId.indexOf('-50b6476d:13c5bfc1043:-7fef') == -1 && sessionStorage.RoleId.indexOf('-50b6476d:13c5bfc1043:-7fe9') == -1) {
            Ext.Msg.alert('错误', '您无权访问党组会议，请联系管理员!', Ext.emptyFn);
            return;
        }
        sessionStorage.MeetingCategory = 'dz';
        //
        //this.redirectTo('main');
        //直接进入当前最新会议的议题
        //获取当前最新会议
        this.toTopic();
    },
    showMainBg: function () {
        if (sessionStorage.RoleId.indexOf('-50b6476d:13c5bfc1043:-7fef') == -1 && sessionStorage.RoleId.indexOf('-50b6476d:13c5bfc1043:-7fe9') == -1
        && sessionStorage.RoleId.indexOf('-50b6476d:13c5bfc1043:-7fee') == -1 && sessionStorage.RoleId.indexOf('-50b6476d:13c5bfc1043:-7fe7') == -1) {
            Ext.Msg.alert('错误', '您无权访问办公会议，请联系管理员!', Ext.emptyFn);
            return;
        }
        sessionStorage.MeetingCategory = 'bg';
        //this.redirectTo('main');
        this.toTopic();
    },
    showMainFjz: function () {
        if (sessionStorage.RoleId.indexOf('-5c36c563:13f5fa82ca4:-7931') == -1) {
            Ext.Msg.alert('错误', '您无权访问分局长会议，请联系管理员!', Ext.emptyFn);
            return;
        }
        sessionStorage.MeetingCategory = 'fjz';
        //this.redirectTo('main');
        this.toTopic();
    },
    showMainQt: function () {
        sessionStorage.MeetingCategory = 'qt';
        //this.redirectTo('main');
        //直接进入当前最新会议的议题
        //获取当前最新会议
        this.toTopic();
    },
    showMy: function () {
        this.redirectTo("mymeeting");
    },
    toTopic: function () {
        Ext.Viewport.mask({ xtype: 'myloadmask', message: '加载中' + commLib.loadingText });
        //直接进入当前最新会议的议题
        //获取当前最新会议
        Ext.data.JsonP.request({
            scope: this,
            url: commLib.Website + '/ashx/MeetingHandler.ashx?method=getlastid&category=' + sessionStorage.MeetingCategory + '&userid=' + sessionStorage.UserId, //记录当前用户的登录时间，作为签到
            success: function (result, request) {
                Ext.Viewport.unmask();
                if (result.success) {
                    //获取ID成功之后，直接跳转到议题界面
                    //记录会议ID   
                    Ext.Viewport.unmask();
                    if (result.ResponseData == null) {
                        var cag = "";
                        if (sessionStorage.MeetingCategory == 'bg') {
                            cag = "办公会议";
                        }
                        else if (sessionStorage.MeetingCategory == 'dz') {
                            cag = "党组会议";
                        }
                        else if (sessionStorage.MeetingCategory == 'fjz') {
                            cag = "分局长会议";
                        }
                        else if (sessionStorage.MeetingCategory == 'qt') {
                            cag = "其他会议";
                        }
                        Ext.Msg.alert('提示', '当前没有在进行的' + cag + "!", Ext.emptyFn);
                    }
                    else {
                        sessionStorage.MeetingId = result.ResponseData.ItemArray[0];
                        sessionStorage.VideoRoomNumber = result.ResponseData.ItemArray[2];
                        sessionStorage.HostEmail = result.ResponseData.ItemArray[3];
                        sessionStorage.HostPass = result.ResponseData.ItemArray[4];
                        sessionStorage.HostId = result.ResponseData.ItemArray[5];
                        sessionStorage.MeetingTitle = result.ResponseData.ItemArray[6];
                        this.redirectTo('meetingtopic');
                    }
                }
                else {
                    Ext.Viewport.unmask();
                    Ext.Msg.alert('错误', result.Message, Ext.emptyFn);
                }
            },
            failure: function (response) {
                Ext.Viewport.unmask();
                alert("服务器连接错误！");
            }
        });
    }
})